#include <thread>
#include <iostream>
#include <mutex>
#include <cstdlib>
#include <unistd.h>
int s = 0;
int i = 0;
std::mutex mutex;
void threadF1()
{
	while (i <= 100) {
		{
			std::lock_guard<std::mutex> lck(mutex); 
			s += i;
			i++;
			std::cout << "1" << std::endl;
		}

		usleep(10);
	}
}
void threadF2()
{
	while (i <= 100) {
		{
			std::lock_guard<std::mutex> lck(mutex); 
			s += i;
			i++;
			std::cout << "2" << std::endl;
		}
		usleep(10);
	}
}
int main()
{
	std::thread t1(threadF1);
	std::thread *t2 = new std::thread(threadF2);

	t1.join();
	t2->join();
	delete t2;
	std::cout << s << std::endl;
	return 0;
}
